package com.sochinchou.res.components;

import com.sochinchou.res.utils.Constants;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.sochinchou.res.R;



public class MyActivity extends Activity{

	private static final String TAG = "=== MyActivity ===";

	
	private Context mContext;
	private ProgressDialog mProgressDialog;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Log.e(TAG, "onCreate() >>>>>");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_layout_main);
        mContext = this;
        new Thread(){

        	
    		@Override
    		public void run() {
    			while(true){

    				try {
    					Thread.sleep(2000);
    				} catch (InterruptedException e) {
    					e.printStackTrace();
    				}
    				
    				MyWidgetProvider.updateWidget(mContext);
    			}
    		}       	
        }.start();
        
//        init();
//        initViews();
    }

    private void init(){
    	Log.e(TAG, "init() >>>>>");
    	//To Do
    }
    
    private void initViews(){
    	Log.e(TAG, "initViews() >>>>>");
    	mContext = this;
    	mProgressDialog = new ProgressDialog(mContext);
		//  To Do
    }
    
	@Override
	protected void onResume() {
    	Log.e(TAG, "onResume() >>>>>");
		super.onResume();
	}

	@Override
	protected void onPause() {
    	Log.e(TAG, "onPause() >>>>>");
		super.onPause();
	}

	@Override
	protected void onDestroy() {
    	Log.e(TAG, "onDestroy() >>>>>");
		super.onDestroy();
	}

	@Override
	public void onBackPressed() {
		Log.e(TAG, "onBackPressed() >>>>>");
		super.onBackPressed();
	}
	
	

	
	private class MyTask extends AsyncTask<Void, Void, Void>{
		
		private static final String TAG = "=== MyTask ===";
		
		@Override
		protected Void doInBackground(Void... params) {
			Log.i(TAG, "doInBackground() >>>");
			return null;
		}

		@Override
		protected void onPreExecute() {
			Log.i(TAG, "onPreExecute() >>>");
			super.onPreExecute();
			mProgressDialog.setMessage(getString(android.R.string.ok));
			mProgressDialog.show();
		}

		@Override
		protected void onPostExecute(Void result) {
			Log.i(TAG, "onPostExecute() >>>");
			super.onPostExecute(result);
			if(mProgressDialog.isShowing())
				mProgressDialog.dismiss();
		}		
	}
	

	
	private static final int MSG_HANDLER1 = 100;
	private static final int MSG_HANDLER2 = 101; 
	private Handler mHandler = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			switch(msg.what){
			case MSG_HANDLER1:
				break;
				
			case MSG_HANDLER2:
				break;
			}
		}		
	};
	
	private void logger(String strLog){
		if(Constants.DEBUG)
			Log.d(TAG, strLog);
	}
	
	private void logger(String tag, String strLog){
		if(Constants.DEBUG)
			Log.d(tag, strLog);
	}
}